package com.xwh.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xwh.mapper.StudentMapper;
import com.xwh.pojo.entity.Student;
import com.xwh.pojo.vo.StudentVo;
import com.xwh.service.IStudentService;
import com.xwh.util.Result;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Objects;

/**
 * @author 向文豪
 * @program: springboot0412
 * @description:
 * @date 2023/4/12 19:42
 */
@Service
public class StudentServiceImpl implements IStudentService {

    @Autowired
    private StudentMapper studentMapper;
    @Override
    public Result findPage(Integer current, Integer pageSize, StudentVo studentVo) {

        Page<Student> page = new Page<>(current,pageSize);
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        if(StringUtils.hasText(studentVo.getSid())){
            wrapper.eq("sid",studentVo.getSid());
        }
        if (StringUtils.hasText(studentVo.getSname())){
            wrapper.like("sname",studentVo.getSname());
        }
        if(StringUtils.hasText(studentVo.getAge())){
            wrapper.ge("age",studentVo.getAge());
        }
        if(StringUtils.hasText(studentVo.getSid())){
            wrapper.eq("ccis",studentVo.getCcid());
        }
      studentMapper.findPage(page,wrapper);
        return new Result(200,"查询学生信息成功",page);


    }

    @Override
    public Result findAll() {
        List<Student> students = studentMapper.selectList(null);
        return new Result(200,"查询信息成功",students);
    }

    @Override
    public Result findById(Integer sid) {
        Student student = studentMapper.selectById(sid);
        return new Result(200,"查询学生信息成功",student);
    }

    @Override
    public Result insert(Student student) {
        return new Result(200,"添加成功",studentMapper.insert(student));
    }

    @Override
    public Result updateById(Student student) {
        return new Result(200,"查询信息成功",studentMapper.updateById(student));
    }

    @Override
    public Result deleteById(Integer id) {
        return new Result(200,"删除学生信息成功",studentMapper.deleteById(id));
    }

    @Override
    public Result deleteByIds(List<Integer> ids) {
        return new Result(200,"删除成功",studentMapper.deleteBatchIds(ids));
    }

    @Override
    public Result getPage(IPage<Student> iPage, Wrapper<Student> wrapper) {
        return new Result(200,"分页查询成功",studentMapper.selectPage(iPage,wrapper));
    }
}
